package com.train.mgr.modules.biz.controller;

import com.train.common.model.PageParam;
import com.train.common.model.PageResult;
import com.train.common.model.R;
import com.train.mgr.modules.biz.dto.request.LessonReqDTO;
import com.train.mgr.modules.biz.dto.response.LessonDetailRespDTO;
import com.train.mgr.modules.biz.dto.response.LessonListRespDTO;
import com.train.mgr.modules.biz.entity.Lesson;
import com.train.mgr.modules.biz.service.ILessonService;
import com.train.mgr.modules.system.dto.request.groups.Insert;
import com.train.mgr.modules.system.dto.request.groups.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课时表 前端控制器
 * @author cxg
 * @date 2025-09-30
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@Api( tags = "课时管理[企业端]")
@RequestMapping("/lesson")
public class LessonController {

    private final ILessonService lessonService;

    /**
     * 功能描述:单个获取
     * @author: cxg
     * @date: 2025-09-30
     */
    @GetMapping("/getById/{id}")
    @ApiOperation("查询详情")
    public R<LessonDetailRespDTO> getDetailById(@PathVariable(name = "id") Long id) {
        return R.succeed(lessonService.getDetailById(id));
    }


    /**
     * 条件 分页查询
     * @author: cxg
     * @date: 2025-09-30
     */
    @GetMapping("/findList")
    @ApiOperation("课时列表")
    public R<List<LessonListRespDTO>> findList(@RequestParam(name = "courseId", required = true) Long courseId) {
        return R.succeed(lessonService.findList(courseId));
    }

    /**
	 * 新增
     * @author: cxg
     * @date: 2025-09-30
	 */
    @PostMapping("/add")
    @ApiOperation("新增课时")
    public R<Boolean> add(@RequestBody @Validated(Insert.class) LessonReqDTO body) {
        Boolean result = lessonService.add(body);
        return R.succeed(result);
    }

	/**
	 * 更新
     * @author: cxg
     * @date: 2025-09-30
	 */
    @PostMapping("/update")
    @ApiOperation("更新课时")
    public R<Boolean> update(@RequestBody  @Validated(Update.class) LessonReqDTO body) {
        Boolean result = lessonService.update(body);
        return R.succeed(result);
    }

    @PostMapping("/publish/{id}")
    @ApiOperation("发布课程")
    public R<Boolean> publish(@PathVariable(name = "id") Long id) {
        Boolean result = lessonService.publish(id);
        return R.succeed(result);
    }

    @PostMapping("/unPublish/{id}")
    @ApiOperation("取消发布课程")
    public R<Boolean> unPublish(@PathVariable(name = "id") Long id) {
        Boolean result = lessonService.unPublish(id);
        return R.succeed(result);
    }
	/**
	 * 删除
     * @author: cxg
     * @date: 2025-09-30
	 */
    @DeleteMapping("/delete")
    @ApiOperation("删除课时")
    public R<Boolean> delete(@RequestParam(name = "lessonId") Long lessonId) {
          Boolean result = lessonService.deleteById(lessonId);
          return R.succeed(result);
    }
}
